package jmine.tec.persist.schema.impl.elements.type;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;

import jmine.tec.persist.schema.impl.elements.ColumnTypeElement;

import org.hibernate.type.CustomType;
import org.hibernate.type.NullableType;
import org.hibernate.type.Type;

/**
 * Strategy para lidar com campos de date.
 * 
 * @author lundberg
 */
public class DateTypeStrategy implements TypeStrategy {

    /**
     * {@inheritDoc}
     */
    public List<String> checkUserDefinedValues(ColumnTypeElement columnType, Class<?> returnedClass) {
        return Collections.emptyList();
    }

    /**
     * {@inheritDoc}
     */
    public int correctSqlType(Type type, int current) {
        if (type instanceof NullableType) {
            return ((NullableType) type).sqlType();
        } else if (type instanceof CustomType) {
            CustomType t = ((CustomType) type);
            if (t.sqlTypes(null).length == 1) {
                return t.sqlTypes(null)[0];
            }
        }
        return current;
    }

    /**
     * {@inheritDoc}
     */
    public Set<AllowedValue> getAllowedValues(Class<?> returnedClass) {
        throw new UnsupportedOperationException();
    }

    /**
     * {@inheritDoc}
     */
    public boolean hasLimitedAllowedValues() {
        return false;
    }

    /**
     * {@inheritDoc}
     */
    public void inferTypeParameters(ColumnTypeElement columnType, Class<?> returnedClass) {
        return;
    }

    /**
     * {@inheritDoc}
     */
    public boolean matches(ColumnTypeElement columnTypeElement, Type type) {
        return Date.class.isAssignableFrom(type.getReturnedClass());
    }
}
